package cn.jiyun.controller;

import cn.jiyun.pojo.User;
import cn.jiyun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserService userService;
   @RequestMapping("findAll")
   @ResponseBody
    public List<User> findAll(){
       List<User> list=userService.findAll();
       return list;
   }
   @RequestMapping("deleteById/{id}")
    @ResponseBody
    public Boolean deleteById(@PathVariable("id") Integer id){
       System.out.println("id==============="+id);
      Boolean b= userService.deleteById(id);
      return b;
   }
   @RequestMapping("updateById/{id}")
    @ResponseBody
    public Boolean updateById(@PathVariable("id") Integer id){
       Boolean b=userService.updateById(id);
       return b;
   }
   @RequestMapping("add")
    @ResponseBody
   public List<User> add(){
       User user = new User(5, "王五", 23, "女",3);
       userService.add(user);
       List<User> list=userService.findAll();
       return list;
   }

}
